package com.sm.chapter1;

import java.net.ServerSocket;
import java.net.Socket;

public class TimeServer {
	public static void main(String[] args) {
		int port = 8080;
		if(args!=null && args.length>0){
			
			try{
				port = Integer.parseInt(args[0]);
			}catch(NumberFormatException e){
				
			}
			
		}
		ServerSocket server = null;
		try{
			server = new ServerSocket(port);
			System.out.println("The time Server is start port : "+port);
			Socket socket = null;
			while(true){
				socket = server.accept();
				new Thread(new TimeServerHandle(socket)).start();
				
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		finally{
			if(server !=null ){
				System.out.println("The time server close");
				try{
					server.close();
				}catch(Exception e){
					e.printStackTrace();
				}
				
				server = null;
			}
		}
	}
}
